/* NOTICE

Jim - the Java Image Manager, copyright (c) 2005 Grant Gardner 

Jim is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

Jim is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Jim; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

Created on 27/05/2008

NOTICE */

package au.com.lastweekend.jim.imagebase;

import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;

import au.com.lastweekend.jim.io.metadata.Directory;

public class ImageFileDirectory extends Directory {

    private static final HashMap<Integer, String> TAG_NAME_MAP = new HashMap<Integer, String>();

    private static final Logger LOG = Logger.getLogger(ImageFileDirectory.class);

    public static final int TAG_CANONICAL_PATH = 2;
    public static final int TAG_LAST_MODIFIED = 3;

    private static final int FMT_STRING = 0;
    private static final int FMT_DATE = 1;

    static {
        TAG_NAME_MAP.put(TAG_CANONICAL_PATH, "Canonical Path");
        TAG_NAME_MAP.put(TAG_LAST_MODIFIED, "Last modified");
    }

    public ImageFileDirectory(File imageFile) {

        super(null);
        this.setDescriptor(new ImageFileDescriptor(this));
        setImageFile(imageFile);
    }

    private void setImageFile(File imageFile) {

        String canonicalPath;
        try {
            canonicalPath = imageFile.getCanonicalPath();
        } catch (IOException e) {
            canonicalPath = imageFile.getAbsolutePath();
            LOG.warn("Unable to canonicalise path");

        }
        this.setTag(TAG_CANONICAL_PATH, FMT_STRING, canonicalPath);
        this.setTag(TAG_LAST_MODIFIED, FMT_DATE, new Date(imageFile.lastModified()));
    }

    @Override
    public String getName() {

        return "Image File";
    }

    @Override
    protected Map<Integer, String> getTagNameMap() {

        return TAG_NAME_MAP;
    }

}
